package org.ispider;

import java.net.MalformedURLException;
import java.net.URL;

public class Utils {

	/**
	 * @param args
	 */
	public static String makeLinks(String text, String mainUrl) {
		if(text.length()>550)
	        text = text.substring(0, 550)+" .... <a href='"+mainUrl+"'>read more</a>";
     	String [] parts = text.split("\\s");
        StringBuffer sb = new StringBuffer();
        // Attempt to convert each item into an URL.   
        for( String item : parts ) try {
            URL url = new URL(item);
            // If possible then replace with anchor...
            sb.append("<a href=\"" + url + "\">"+ url + "</a> " );    
        } catch (MalformedURLException e) {
            // If there was an URL that was not it!...
            sb.append( item + " " );
        }
        
        	return sb.toString();

	}

}
